package com.yn.pet.controller.app;


import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.pc.request.PetQueryRequest;
import com.yn.pet.service.LocationRealtimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@AllArgsConstructor
@RequestMapping("/front/location")
@Api(tags = "app端——实时信息定位")
@Slf4j
public class ALocationRealtimeController {
    private final LocationRealtimeService locationRealtimeService;


    /**
     * 查询实时信息定位列表_某一天的定位信息
     * @param deviceId 设备ID
     * @param time  时间
     * @param locationTypes 定位类型
     * @return List<LocationRealtimeResponse>
     */
    @GetMapping("list")
    @ApiOperation("实时信息定位列表——历史轨迹")
    public AjaxResult list(@RequestParam @NotNull @ApiParam("设备id") Long deviceId,
                           @RequestParam(required = false) @ApiParam("时间") String time,
                           @RequestParam(required = false) @ApiParam("定位类型") String locationTypes){
        log.info("查询实时信息定位列表_某一天的定位信息入参:time:{},locationTypes:{}", time,locationTypes);
        return AjaxResult.success(locationRealtimeService.listInfoByTime(time,deviceId,locationTypes));
    }

    /**
     * 立即定位
     * @param deviceId 设备id
     * @return ImmediateLocationResponse
     */
    @GetMapping("immediate")
    @ApiOperation("获取设备定位信息")
    public AjaxResult deviceLocation(@RequestParam @ApiParam("设备id") Long deviceId,
                                     @RequestParam @ApiParam("时间字符串") String sendTimeStr){
        log.info("立即定位入参:deviceId,{}", deviceId);
        return AjaxResult.success(locationRealtimeService.getLocationImmediate(deviceId,sendTimeStr));
    }


    /**
     * 立即定位
     * @param deviceId 设备id
     * @return ImmediateLocationResponse
     */
    @PostMapping("immediate")
    @ApiOperation("立即定位")
    public AjaxResult immediate(@RequestParam @ApiParam("设备id") Long deviceId){
        log.info("立即定位入参:deviceId,{}", deviceId);
        return AjaxResult.success("定位成功",locationRealtimeService.getLocation(deviceId));
    }
}
